home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_dates2.arc / SEPARATE.ARC / DAYCNT.C next >
Text File  |  1991-01-10  |  2KB  |  55 lines

  1. /************************************************************************/
  2. /*                *** daycnt.c ***            */
  3. /*                                    */
  4. /* This function returns the number of days of the specified type that    */
  5. /* exist between the two julian dates input, expressed as an signed    */
  6. /* long integer.                            */
  7. /*                                    */
  8. /* The input values to the function, in their proper order, are:    */
  9. /*                                    */
  10. /*  1.  the beginning julian date              ( unsigned long )    */
  11. /*                                    */
  12. /*  2.  the ending julian date                  ( unsigned long )    */
  13. /*                                    */
  14. /*  3.  the numerical code representing the type            */
  15. /*    of days    to be counted ( described below )     ( unsigned int )    */
  16. /*                                    */
  17. /* The following is a list of the codes used to define the        */
  18. /* type of days that are to be counted:                    */
  19. /*                                    */
  20. /*   CODE        - EXPLANATION -                    */
  21. /*                                    */
  22. /*     0  -  all days                            */
  23. /*                                    */
  24. /*     1  -  all days excluding Sundays                    */
  25. /*                                    */
  26. /*     2  -  all days excluding weekends ( Saturdays and Sundays )    */
  27. /*                                    */
  28. /*   NOTE -  input of any code not listed above will be            */
  29. /*         interpreted as code 0.                    */
  30. /*                                    */
  31. /************************************************************************/
  32.  
  33. extern int dow( unsigned long );
  34.  
  35. long daycnt( juldt1, juldt2, excl )
  36.  
  37. long juldt1, juldt2;
  38. unsigned int excl;
  39.  
  40. {
  41.     int  eff = 7 - ( excl = excl > 2 ? 0 : excl );
  42.  
  43.     if ( !excl-- ) return( juldt2 - juldt1 );
  44.  
  45.     if ( juldt1 > juldt2 ) return( -daycnt( juldt2, juldt1, ++excl ) );
  46.     else
  47.     {
  48.          juldt1 -= !dow( juldt1 ) + ( excl && !( dow( juldt1 ) % 6 ) );
  49.          juldt2 -= !dow( juldt2 ) + ( excl && !( dow( juldt2 ) % 6 ) );
  50.     }
  51.  
  52.     return( ( juldt2 - juldt1 ) / 7 * eff +
  53.         ( dow( juldt2 ) - dow( juldt1 ) + eff ) % eff );
  54. }
  55.